package com.atguigu.gmall.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Properties;

/**
 * Author: Felix
 * Date: 2022/1/13
 * Desc: 日志采集服务
 */
@RestController
@Slf4j
public class LoggerController {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    //private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerController.class);
    @RequestMapping("/applog")
    public String logger(@RequestParam("param") String logStr){
        //打印输出到控制台
        //System.out.println(logStr);
        //落盘---使用第三方记录日志的框架 logback完成
        log.info(logStr);
        //发送到kafka主题
        kafkaTemplate.send("ods_base_log",logStr);
        return "success";
    }
}
